#include "stdafx.h"
#include "ServerDataManage.h"
#include "ServerDoc.h"
#include "PCControl.h"



CServerDataManage::CServerDataManage(void)
	: m_dwLastCommand(0)
{
}


CServerDataManage::~CServerDataManage(void)
{
}


void CServerDataManage::afterAcceSock(const BaseSocket& b)
{
	
	LPTSTR lpszIP = ANSIToUnicode(b.getIp());
	int nPort = b.getPort();
	CFrameWndEx* wnd = (CFrameWndEx*)AfxGetApp()->m_pMainWnd;
	CServerDoc* pDoc = (CServerDoc*)wnd->GetActiveView()->GetDocument();

	pDoc->AddClient(b);
	
	delete lpszIP;
}


void CServerDataManage::afterRecvData(const BaseSocket * const b, const PerIoData * const data)
{

	CFrameWndEx* wnd = (CFrameWndEx*)AfxGetApp()->m_pMainWnd;
	CServerDoc* pDoc = (CServerDoc*)wnd->GetActiveView()->GetDocument();
	Package* pack = (Package*)data->getMsg();
	PROCESS_INFO_NET_ALL stAllInfo;
	switch (pack->dwCommand)
	{
	case RESPOND_PROCESS:
		stAllInfo = pack->info.stAllInfo;
		pDoc->UpdateProcessInfo(RESPOND_PROCESS, (LPARAM)&stAllInfo);
		//wnd->SendMessage(WM_UPDATEINFOVIEW, RESPOND_PROCESS, (LPARAM)pstAllInfo);
		//pDoc->UpdateAllViews(NULL, RESPOND_PROCESS, (CObject*)pstAllInfo);

		break;
	default:
		break;
	}




	//if (g_dwLastCommand == 0)
	//{
	//	PackageHead* pstHead = (PackageHead*)data->getMsg();
	//	g_dwLastCommand = pstHead->dwCommand;
	//}
	//else
	//{
	//	CFrameWndEx* wnd = (CFrameWndEx*)AfxGetApp()->m_pMainWnd;
	//	CServerDoc* pDoc = (CServerDoc*)wnd->GetActiveView()->GetDocument();

	//	PROCESS_INFO_NET_ALL* pstAllInfo;
	//	switch (g_dwLastCommand)
	//	{
	//	case RESPOND_PROCESS:
	//		pstAllInfo = (PROCESS_INFO_NET_ALL*)data->getMsg();
	//		pDoc->UpdateProcessInfo(RESPOND_PROCESS, (LPARAM)pstAllInfo);
	//		//wnd->SendMessage(WM_UPDATEINFOVIEW, RESPOND_PROCESS, (LPARAM)pstAllInfo);
	//		//pDoc->UpdateAllViews(NULL, RESPOND_PROCESS, (CObject*)pstAllInfo);
	//	
	//		break;
	//	default:
	//		break;
	//	}

	//	g_dwLastCommand = 0;
	//}


	//tagPackage stPackage = data->getMsg()
	//switch (switch_on)
	//{
	//default:
	//	break;
	//}

	//PROCESS_INFO_NET_ALL* pstAllInfo = (PROCESS_INFO_NET_ALL*)data->getMsg();
	//for (int i = 0; pstAllInfo->nCount; i++)
	//{
	//	pstAllInfo->stInfo[i];
	//}


}